package com.xw.unification.condition;

import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;

import java.util.Optional;

import com.xw.unification.constant.UnificationConstant.RepeatableRequest;

public class UnifiedRepeatableRequestCondition extends UnificationCondition {

    @Override
    public boolean matchesCondition(ConditionContext context, AnnotatedTypeMetadata metadata) {
        return "true".equalsIgnoreCase(
                Optional.ofNullable(context.getEnvironment().getProperty(RepeatableRequest.ENABLE_PROPERTY_KEY))
                        .orElse(String.valueOf(RepeatableRequest.DEFAULT_ENABLE))
        );
    }
}
